import { defineAsyncComponent } from 'vue'
export const registerBomchecklAsyncComponents = app => {
  const modules = import.meta.glob('/src/views/plm/containManagement/bomCheck/*.vue')
  //新添加的地方，详情采用我们自己的详情，新增任务tab
  modules['/bomDetail.vue'] = () =>
    import(
      './../../capp/processManagement/processObjectViewer/OutputLink/components/bomPartsDetail.vue'
    )
  modules['/processTask.vue'] = () =>
    import(
      './../../capp/processManagement/processBom/ProductLibraryList/PartsInfo/ProcessTask/Index.vue'
    )
  for (const path in modules) {
    const result = path.match(/.*\/(.+).vue$/)
    if (result) {
      const name = result[1]
      const component = modules[path]
      app.component(name, defineAsyncComponent(component))
    }
  }
}

/**
 * https://www.jianshu.com/p/ff9fde39e9b0
 * https://blog.csdn.net/qq_24719349/article/details/121749053
 *
 * https://blog.csdn.net/weixin_43294560/article/details/117336984
 */
export const addRoutes = () => {
  const modulesFiles = import.meta.glob('./modules/*.js', { eager: true })
  let modules = {}
  for (let [key, value] of Object.entries(modulesFiles)) {

    let moduleName = key.replace(/^\.\/(.*)\.\w+$/, '$1')
    const name = moduleName.split('/')[1]
    // 具体内容， 都是每个JS中返回值
    modules[name] = value.default
  }
  return modules
}